# -*- coding: utf-8 -*-
"""
@Time    : 2024/6/26 20:08 
@Author  : ZhangShenao 
@File    : operations.py 
@Desc    : 集合的运算
"""

# 使用intersection()函数,计算多个set的交集
s1 = {1, 2, 3}
s2 = {2, 3, 4}
s3 = {3, 4, 5}
inter = s1.intersection(s2, s3)
print(f'intersection: {inter}')  # {3}

# set的&运算与intersection()函数等价
inter = s1 & s2 & s3
print(f'intersection: {inter}')  # {3}

# 使用union()函数,计算多个set的并集
uni = s1.union(s2, s3)
print(f'union: {uni}')  # {1, 2, 3, 4, 5}

# set的|运算与union()函数等价
uni = s1 | s2 | s3
print(f'union: {uni}')  # {1, 2, 3, 4, 5}

# 使用difference()函数,计算两个set的差集
diff = s1.difference(s2, s3)
print(f'difference: {diff}')  # {1}

# set的-运算与difference()函数等价
diff = s1 - s2 - s3
print(f'difference: {diff}')  # {1}

# 使用issubset()函数,判断一个set是否是另一个set的子集
s1 = {1, 2, 3, 4, 5}
s2 = {1, 2, 3}
s3 = {4, 5, 6}
print(f's2 is s1\'s sub set? {s2.issubset(s1)}')  # True
print(f's3 is s1\'s sub set? {s3.issubset(s1)}')  # False

# 使用issuperset()函数,判断一个set是否是另一个set的超集
print(f's1 is s2\'s super set? {s1.issuperset(s2)}')  # True
print(f's1 is s3\'s super set? {s1.issuperset(s3)}')  # False

# 使用len()函数,获取set中的元素个数
print(f'length of s1 is: {len(s1)}')  # 5
